﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;
using System.Configuration;



namespace Final
{
    public partial class Email : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }

        protected void btnSend_Click(object sender, EventArgs e)
        {
                MailMessage mail = new MailMessage();
                mail.To.Add(txtTo.Text);
                mail.From = new MailAddress("junhao0905@gmail.com");
                mail.Subject = txtTitle.Text;
                mail.Body = txtMessage.Text;
                mail.IsBodyHtml = true;
                SmtpClient smtp = new SmtpClient();
                smtp.Host = "smtp.gmail.com";
                smtp.Port = 587;
                smtp.UseDefaultCredentials = false;
                smtp.Credentials = new System.Net.NetworkCredential
                ("junhao0905@gmail.com", "92724798");
                smtp.EnableSsl = true; smtp.Send(mail);
                txtTo.Text = "";
                txtTitle.Text = "";
                txtMessage.Text = "";
                //Response.Redirect("email.aspx");
                string alertScript = String.Format("<Script Language='javascript'> alert('{0}');</script>", "Email Send Successfully!");
                Page.ClientScript.RegisterStartupScript(this.GetType(), "Key", alertScript, false);  
            
            
        }
    }
}